export const useCrypto = () => {
    const crypto = require('crypto');
    const encryptionKey = 'EncryptionKey';

    // 加密函数
    function encryptText<T>(text: T) {
        const cipher = crypto.createCipher('aes-256-cbc', encryptionKey);
        let encryptedData = cipher.update(text, 'utf8', 'hex');
        encryptedData += cipher.final('hex');
        return encryptedData;
    }

    // 解密函数
    function decryptText<T>(encryptedText: T) {
        const decipher = crypto.createDecipher('aes-256-cbc', encryptionKey);
        let decryptedData = decipher.update(encryptedText, 'hex', 'utf8');
        decryptedData += decipher.final('utf8');
        return decryptedData;
    }

    return {
        encryptText,
        decryptText
    }
}